package com.jinzecloud.fiction.config;

import com.jinzecloud.fiction.interceptor.HandlerInterceptorAdapter;
import com.jinzecloud.fiction.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor;

/**
     * 用注解方式配置拦截器
     */
@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    RedisUtils redisUtils;
    @Value("${fiction.admin.token}")
    String tokenPrefix;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new HandlerInterceptorAdapter(redisUtils));
        //添加拦截器
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new HandlerInterceptorAdapter(redisUtils,tokenPrefix));
        //排除的路径
        interceptorRegistration.excludePathPatterns("/fiction/login");
//        interceptorRegistration.excludePathPatterns("/logout");
        interceptorRegistration.excludePathPatterns("/fiction/captchaJpg");
        //将这个controller放行
        interceptorRegistration.excludePathPatterns("/error");
        //拦截全部
        interceptorRegistration.addPathPatterns("/**");
    }
}

